Option Explicit

Dim doc
Set doc = application.ActiveDocument
main
sub main()
	If ValidateServer(doc) = 0 Then
	    msgbox "Server validation failed."
	    exit sub
	End If
	Dim LayerCountNum,isTpins,isBpins,isTpin,isBpin,activeLayer
	LayerCountNum=doc.LayerCount

	isTpin  = doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideTop )
	activeLayer= application.gui.ActiveRouteLayer

	if (activeLayer="1") Then
	
		if ( isTpin=False ) Then
			isTpin = not isTpin
			doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideTop)= isTpin
		else 
			isTpin = not isTpin
			doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideTop)= isTpin
		end if

	end if

	isBpin = doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideBottom)
	if (activeLayer=LayerCountNum) Then
	
		if ( isBpin=False ) Then
		'application.Gui.display "false"
		isBpin = not isBpin
		doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideBottom)= isBpin
		
		else 
			'application.Gui.display "True"
			isBpin = not isBpin
			doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideBottom)= isBpin
		end if
		
	end if	
	
	if (activeLayer<>"1" AND activeLayer<>LayerCountNum) Then
		doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideTop)= False
		doc.ActiveView.DisplayControl.PartItems (epcbDCPinNumbers,epcbSideBottom)=False
	end if
end sub

' Function to validate document
Private Function ValidateServer(docObj)
    Dim key, licenseServer, licenseToken
    key = docObj.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    docObj.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

